<template>
	<view>
		<view class="top u-p-20">
			<u-search placeholder="搜索商品名字" v-model="keyword" @custom="toSearch"></u-search>
		</view>
		
		<view class="uni-list">
			
				<view class="car_home_foods">
					<view class="car_food_item" v-for="(item,index) in goodslist" :key="item.id">
						
						<view class="car_food_info">
							<view class="car_food_img">
								<block v-if="item.id">
									<image class="food_img" :src="item.cover_url" mode="aspectFill"></image>
								</block>
								<block v-else>
									<image class="food_img default" src="@/static/default_good1.png" mode="aspectFill">
									</image>
								</block>
							</view>
							<view class="car_food_right">
								<view class="car_food_top">
									<view class="car_food_left">
										<view class="car_food_name">{{item.title}}
										</view>
										<view class="car_food_label">{{item.description}}</view>
										<view class="car_food_label2" >
										<span v-if="item.is_on == 1">上架</span>
										<span v-if="item.is_on == 0">下架</span>
										</view>
									</view>
									<view class="car_edit_right">
										<image class="car_del_icon" @click="editgoods(item.id)" :lazy-load="true"
											src="/static/trash.png" style="width: 27rpx;height: 33rpx;"></image>
									</view>
								</view>
								<view class="car_food_bottom">
									<view class="car_food_price">
										￥ {{item.price?parseFloat(item.price).toFixed(2):'0.00'}}
									</view>
								
								</view>
							</view>
						</view>
					</view>
				</view>
		
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				goodslist:[],
				current:1,
				keyword: '',
			}
		},
		onShow() {
			this.init()
		},
		methods: {
			async init() {
				const params = {
					current:this.current,
					title:this.keyword,
					keyword: '',
				}
				const res = await this.$u.api.admingoods(params)		
				this.goodslist = [...this.goodslist,...res.data] 
			},
			toSearch(){
				// console.log(this.keyword)
				this.goodslist = []
				this.current =1 
				this.init()
				setTimeout(()=>{
					this.keyword = ''
				},5000)
			    
			},
			async editgoods(good) {
				console.log(good)
				const res = await this.$u.api.editgoods(good)
				this.$u.toast('修改上下架成功')
				this.goodslist = []
				this.init()
			},
			//下拉更多 重新获取数据，带上分页参数
			onReachBottom() {
				// this.$u.toast('下拉加载中...')
				uni.showToast({
					title:'加载中...',
					icon:'loading',
				})
				this.current = this.current + 1
				this.init()
			},

		}
	}
</script>

<style scoped lang="scss">
	/* #ifdef H5 */
	.top {
		position: sticky;
		z-index: 9999;
		top: 80rpx;
	}
	/* #endif */
	/* #ifndef H5 */
	.top {
		position: sticky;
		z-index: 9999;
		top: 0rpx;
	}
	/* #endif */
	.car_home_box {
		font-size: 24rpx;

		.all_select_box {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 20rpx;
			box-sizing: border-box;
			font-size: 22rpx;
		}

		.car_home_name {
			display: flex;
			justify-content: flex-start;
			align-items: center;
			padding: 20rpx;
			box-sizing: border-box;

			view {
				font-weight: bold;
				font-size: 26rpx;
			}
		}
	}

	.car_home_foods {
		background-color: #ffffff;

		.car_food_item {
			display: flex;
			justify-content: flex-start;
			align-items: center;
			padding: 20rpx;
			box-sizing: border-box;
			border-bottom: 2rpx solid #eaeaea;

			&:last-of-type {
				border-bottom: 0;
			}

			.car_food_info {
				display: flex;
				justify-content: space-between;
				align-items: stretch;
				width: 100%;

				.car_food_img {
					width: 160rpx;
					height: 160rpx;
					border: 2rpx solid #dfe2e7;
					box-sizing: border-box;
					margin-right: 20rpx;
					border-radius: 10rpx;
					overflow: hidden;
					position: relative;

					.food_img {
						width: 100% !important;
						height: 100%;
						border-radius: 10rpx;
					}
				}

				.car_food_right {
					width: 72%;
					display: flex;
					flex-wrap: wrap;
					align-content: space-between;

					.car_food_top {
						width: 100%;
						display: flex;
						justify-content: space-between;
						align-items: flex-start;

						.car_food_left {
							width: 75%;

							.car_food_name {
								font-size: 20rpx;
								font-weight: bold;
								margin: 5rpx 0;
							}

							.car_food_remark {
								// color: #868ea4;
								// font-style: italic;
								font-size: 24rpx;
								margin-bottom: 5rpx;
							}

							.car_food_label {
								color: #7E7E7E;
								font-size: 20rpx;
								margin-bottom: 5rpx;
							}
							.car_food_label2 {
								color: #ff9900;
								font-size: 20rpx;
								margin-bottom: 5rpx;
							}
						}

						.car_edit_right {
							display: flex;
							align-items: center;
							justify-content: flex-end;

							.car_edit_btn {
								color: #DB0E7E;
								font-size: 24rpx;
								font-weight: bold;
								font-smooth: Roboto;
								display: inline-block;
								padding: 5rpx 15rpx;
								border-radius: 30rpx;
								border: 1px solid #DB0E7E;
								margin-right: 20rpx;
							}

							.car_del_icon {
								width: 24rpx;
								height: 30rpx;
							}
						}

						text {
							font-weight: bold;
							font-size: 28rpx;
						}
					}

					.car_food_bottom {
						width: 100%;
						display: flex;
						justify-content: space-between;
						align-items: center;

						.car_food_price {
							color: #DB0E7E;
							font-size: 26rpx;
							font-weight: 500;

							text {
								color: #8E8E8E;
								font-size: 22rpx;
								text-decoration: line-through;
								margin-left: 15rpx;
								font-weight: 400;
							}
						}
					}
				}
			}
		}
	}

	.fixed_footer_next {
		background: #DB0E7E;
		position: fixed;
		width: calc(100% - 50rpx);
		left: 25rpx;
		right: 25rpx;
		bottom: calc(var(--window-bottom, 0) + 30rpx);
		z-index: 10;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 20rpx;
		box-sizing: border-box;
		font-size: 26rpx;
		// box-shadow: 0 -1rpx 30rpx #cccccc;
		border-radius: 10rpx;
	}

	.next_box {
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;

		.next_num {
			color: #ffffff;
			width: 20%;
			text-align: left;

			view {
				width: 44rpx;
				height: 44rpx;
				border-radius: 50%;
				border: 1px solid #ffffff;
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}

		.next_price {
			width: 20%;
			color: #ffffff;
			text-align: right;
		}

		.next_txt {
			width: 30%;
			color: #ffffff;
			font-size: 26rpx;
			text-align: center;
		}
	}

	// 计数器 加减样式
	.info_num {
		display: flex;
		justify-content: space-between;
		align-items: center;
		text-align: center;
		height: 50rpx;

		.minus {
			width: 40rpx;
			height: 40rpx;
			font-size: 40rpx;
			font-weight: bold;
			display: flex;
			justify-content: center;
			align-items: center;
			color: #ADB5BD;

			// border: 5rpx solid #ADB5BD;
			// border-radius: 8rpx;
			image {
				width: 40rpx;
				height: 40rpx;
			}

			&.active {
				color: #000000;
				border-color: #000000;
			}

			.txt {
				height: 42rpx;
				line-height: 38rpx;
				/* #ifdef MP-ALIPAY */
				line-height: 35rpx;
				/* #endif */
			}
		}

		.plus {
			width: 40rpx;
			height: 40rpx;
			font-size: 40rpx;
			font-weight: bold;
			display: flex;
			justify-content: center;
			align-items: center;
			color: #ADB5BD;

			// border: 5rpx solid #ADB5BD;
			// border-radius: 8rpx;
			image {
				width: 40rpx;
				height: 40rpx;
			}

			&.active {
				color: #000000;
				border-color: #000000;
			}

			.txt {
				height: 42rpx;
				line-height: 38rpx;
				/* #ifdef MP-ALIPAY */
				line-height: 35rpx;
				/* #endif */
			}
		}

		input {
			width: 100rpx;
			color: #000000;
			font-size: 28rpx;
		}

		.number {
			width: 100rpx;
			height: 40rpx;
			color: #000000;
			font-size: 28rpx;
			font-weight: bold;
		}
	}

	.car {
		padding-bottom: 220rpx;
	}

	.car_del_icon {
		margin-right: 15rpx;
	}

	.no_car_data {
		text-align: center;
		padding-top: 250rpx;
		color: #333333;
		font-size: 24rpx;

		text {
			color: #DB0E7E;
			margin-left: 5rpx;
		}
	}

	.select_box {
		display: flex;
		justify-content: flex-start;
		align-items: center;

		.select_icon {
			display: block;
			width: 34rpx;
			height: 34rpx !important;
			border: 2rpx solid #cccccc;
			border-radius: 50%;
			margin-right: 20rpx;
			display: flex;
			justify-content: center;
			align-items: center;

			image {
				width: 34rpx;
				height: 34rpx !important;
			}

			&.active {
				background: #DB0E7E;
			}
		}

		.del_all_icon {
			width: 24rpx;
			height: 30rpx;
			margin-left: 20rpx;
		}
	}
	.uni-list-cell {
		justify-content: flex-start
	}
</style>
